module.exports = function(window, document) {
	var apivm = require('../../common/avm.min')(window, document);
	var avm = apivm;
	var api = apivm.api;
	var Component = apivm.Component;
	var $ = apivm.$;
	(function() {
	/*
	 * APICloud JavaScript Library
	 * Copyright (c) 2014 apicloud.com
	 */
	var $kn = {
		byId: function byId(id) {
			return document.getElementById(id);
		},
		ajax: function ajax(p, callback) {
			var _this = this;
			var param = p;
			if (!param.headers) {
				param.headers = {};
			}
			param.headers["x-apicloud-mcm-key"] = "cZKzX7DabDmYyfez";
			if (param.data && param.data.body) {
				param.headers["Content-Type"] = "application/json; charset=utf-8";
			}
			if (param.url) {
				var baseUrl = "https://a8888888888888-pd.apicloud-saas.com/api/";
				param.url = baseUrl + param.url;
			}
			api.ajax(param, function(ret, err) {
				if (callback) callback(ret, err);
				if (ret) {
					var status = ret.status;
					if (status && status == 4001) {
						var didShowLogoutAlert = api.getGlobalData({
							key: "didShowLogoutAlert"
						});

						if (!didShowLogoutAlert) {
							api.setGlobalData({
								key: "didShowLogoutAlert",
								value: true
							});

							_this.setUserInfo("");
							api.alert(
								{
									msg: "登录已失效，请重新登录"
								},
								function() {
									api.setGlobalData({
										key: "didShowLogoutAlert",
										value: false
									});

									api.closeToWin({
										name: "root"
									});
								}
							);
						}
					}
				}
			});
		},
		getUserInfo: function getUserInfo() {
			var value = api.getPrefs({
				key: "userInfo",
				sync: true
			});

			return value ? JSON.parse(value) : "";
		},
		setUserInfo: function setUserInfo(userInfo) {
			api.setPrefs({
				key: "userInfo",
				value: userInfo
			});
		},
		getCurrentCityInfo: function getCurrentCityInfo() {
			var value = api.getPrefs({
				key: "currentCity",
				sync: true
			});

			return value ? JSON.parse(value) : "";
		},
		setCurrentCityInfo: function setCurrentCityInfo(cityInfo) {
			api.setPrefs({
				key: "currentCity",
				value: cityInfo
			});
		},
		getWareTypeList: function getWareTypeList() {
			var value = api.readFile({
				sync: true,
				path: "fs://WareTypeList"
			});

			return value ? JSON.parse(value) : "";
		},
		setWareTypeList: function setWareTypeList(list) {
			api.writeFile({
				path: "fs://WareTypeList",
				data: JSON.stringify(list)
			});
		},
		fitRichText: function fitRichText(richtext, width) {
			var str = '<img style="max-width:' + width + 'px;"';
			var result = richtext.replace(/\<img/gi, str);
			return result;
		}
	};

	var Cityselector = /*@__PURE__*/ (function(Component) {
		function Cityselector(props) {
			Component.call(this, props);
			this.data = {
				dataList: []
			};
		}

		if (Component) Cityselector.__proto__ = Component;
		Cityselector.prototype = Object.create(Component && Component.prototype);
		Cityselector.prototype.constructor = Cityselector;
		Cityselector.prototype.installed = function() {
			this.fnGetCityList();
		};
		Cityselector.prototype.closeAction = function() {
			this.closeFrame();
		};
		Cityselector.prototype.closeFrame = function(currentCity) {
			this.fire("result", currentCity);
		};
		Cityselector.prototype.fnGetCityList = function() {
			var that = this;
			$kn.ajax(
				{
					url: "supportAreas/getSupportAreaList",
					cache: true
				},
				function(ret, err) {
					if (ret && ret.data) {
						var data = ret.data;
						var list = [];
						for (var i = 0; i < data.length; i++) {
							if (data[i].name) {
								list.push(data[i]);
							}
						}
						that.data.dataList = list;
					} else {
						api.toast({
							msg: "获取区域列表失败"
						});
					}
				}
			);
		};
		Cityselector.prototype.fnSelectCity = function(e) {
			var cityInfo = e.currentTarget.dataset.item;
			$kn.setCurrentCityInfo(cityInfo);
			this.closeFrame(cityInfo);
		};
		Cityselector.prototype.render = function() {
			var this$1 = this;
			return apivm.h(
				"view",
				{class: "cityselector-main"},
				apivm.h("safe-area", null),
				apivm.h(
					"text",
					{class: "cityselector-close", onclick: this.closeAction},
					"×"
				),
				apivm.h("text", {class: "cityselector-title"}, "选择所需服务的地区"),
				apivm.h(
					"scroll-view",
					{class: "cityselector-section", "scroll-y": "true"},
					Object.entries(this.data.dataList).map(function(ref) {
						var index$1 = ref[0];
						var item$1 = ref[1];
						return apivm.h(
							"view",
							null,
							apivm.h(
								"text",
								{
									class: "cityselector-city",
									"data-item": item$1,
									onclick: this$1.fnSelectCity
								},
								item$1.name
							)
						);
					})
				)
			);
		};

		return Cityselector;
	})(Component);
	apivm.define("cityselector", Cityselector);
	apivm.render(apivm.h("cityselector", null), "body");
})();

	window['createApp'] = function() {
		apivm.$_start();
	}
	return avm;
}